package top.littlefogcat.shuzihuarongdao;

import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Layout;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import top.littlefogcat.shuzihuarongdao.highscore.HighScoreActivity;
import top.littlefogcat.shuzihuarongdao.main.BoardView;
import top.littlefogcat.shuzihuarongdao.main.GameActivity;
import top.littlefogcat.shuzihuarongdao.server.MusicService;
import top.littlefogcat.shuzihuarongdao.server.MyServer2;


public class MenuActivity extends AppCompatActivity {

    private TextView mTvStartGame;
    private TextView mTvHighScore;
    private TextView mTvExit;
    private TextView mTvsimple;//简单模式
    private RelativeLayout bbbb;
    private Intent intent;
    private TextView mTvputong;
    private BoardView mBoardView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);
        /**
         * 启动背景音乐服务
         */
        Intent a = new Intent(MenuActivity.this, MusicService.class);
        startService(a);

        mTvStartGame = findViewById(R.id.tvStartGame);
        mTvHighScore = findViewById(R.id.tvHighScore);
        mTvExit = findViewById(R.id.tvExit);
        mTvsimple = findViewById(R.id.tvsimple);//背景图片
        bbbb = findViewById(R.id.bbbb);




        mTvStartGame.setOnClickListener(v -> {
            Intent intent = new Intent(MenuActivity.this, GameActivity.class);
            startActivity(intent);
            stopService(a);
        });


//        /**
//         * 这里是普通模式启动4*4宫格
//         */
//        mTvputong.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                try {
//                    Intent intent = new Intent(MenuActivity.this, GameActivity.class);
//                    mBoardView.invalidateRowAndColumn(3, 3);
//                    startActivity(intent);
//                }catch (Exception e) {
//                    e.printStackTrace();
//                }
//
//            }
//        });


        //高分榜
        mTvHighScore.setOnClickListener(v -> {
            Intent intent = new Intent(MenuActivity.this, HighScoreActivity.class);
            startActivity(intent);
        });

        //背景图片
        final int[] flag = {0};
        mTvsimple.setOnClickListener(v -> {

            if (flag[0] == 0) {
                bbbb.setBackgroundResource(R.mipmap.xs);

                flag[0] = 1;
            } else if (flag[0] == 1) {
                bbbb.setBackgroundResource(R.mipmap.vvb);
                flag[0] = 2;
            } else {
                bbbb.setBackgroundResource(R.mipmap.wallpaper);
                flag[0] = 0;
            }

        });

        mTvExit.setOnClickListener(v -> {
            stopService(intent);
            finish();
        });
    }

    protected void onResume() {
        Intent ab = new Intent(MenuActivity.this, MusicService.class);
        startService(ab);
        super.onResume();

    }

    protected void onStop() {
        Intent intt = new Intent(MenuActivity.this, MusicService.class);
        stopService(intt);
        super.onStop();
    }

}

